package com.jerry.mingxing.ui.store;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.StoreBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

/**
 * Created by Administrator on 2016/9/1.
 */
public class RecyclerShowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {

    private List<StoreBean.DataBean.RegionSkusBean> totallist ;
    private Context context;
    private LayoutInflater inflater;
    private MyShowInter myShowInter;

    public RecyclerShowAdapter(List<StoreBean.DataBean.RegionSkusBean> totallist,Context context) {
        this.totallist=totallist;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.mycontentviewrecyclerview_show_item, parent, false);
        MyHolder mholder = new MyHolder(view);

        return mholder;
    }

    @Override
    public void onClick(View v) {
        if (myShowInter!=null){
            myShowInter.onClick(v, (StoreBean.DataBean.RegionSkusBean) v.getTag());
        }
    }

    public interface MyShowInter{
        void onClick(View view, StoreBean.DataBean.RegionSkusBean bean);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       MyHolder myHolder= (MyHolder) holder;
        myHolder.mycontentviewrecyclerview_show_item_sdv.setImageURI(Uri.parse(totallist.get(position).getComponent().getPicUrl()));
        myHolder.mycontentviewrecyclerview_show_item_tv.setText(totallist.get(position).getComponent().getTitle());
        myHolder.itemView.setOnClickListener(this);
        myHolder.itemView.setTag(totallist.get(position));
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return totallist.size();
    }


    static class MyHolder extends RecyclerView.ViewHolder {
         SimpleDraweeView mycontentviewrecyclerview_show_item_sdv;
         TextView mycontentviewrecyclerview_show_item_tv;
        public MyHolder(View itemView) {
            super(itemView);
            mycontentviewrecyclerview_show_item_sdv= (SimpleDraweeView) itemView.findViewById(R.id.mycontentviewrecyclerview_show_item_sdv);
            mycontentviewrecyclerview_show_item_tv= (TextView) itemView.findViewById(R.id.mycontentviewrecyclerview_show_item_tv);
        }
    }
    public void reloadData(List list){
        totallist=list;
        notifyDataSetChanged();
    }
    public void setOnItemClickListener( MyShowInter listener){
        this.myShowInter=listener;
    }

}
